<template>
  <el-dialog v-model="diseaseSearchVisible" title="Shipping address">
    <el-form :model="search">
      <el-form-item label="疾病名称">
        <el-input v-model="search.diseaseName"/>
      </el-form-item>
      <el-form-item label="疾病助记码">
        <el-input v-model="search.diseaseCode"/>
      </el-form-item>
      <el-form-item label="疾病ICD">
        <el-input v-model="search.diseaseICD"/>
      </el-form-item>
      <el-form-item label="疾病类别">
        <el-input v-model="search.diseaseCategory"/>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleSearch">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="disease_list" ref="diseaseTable">
      <el-table-column type="selection"/>
      <el-table-column prop="diseaseCode" label="疾病编码"/>
      <el-table-column prop="diseaseName" label="疾病名称"/>
      <el-table-column prop="diseaseICD" label="国际ICD编码"/>
      <el-table-column prop="diseaseCategory" label="疾病类型"/>
    </el-table>
    <template #footer>
                <span class="dialog-footer">
                  <el-button @click="cancel">
                    Cancel
                  </el-button>
                  <el-button type="primary" @click="confirm">
                    Confirm
                  </el-button>
                </span>
    </template>
  </el-dialog>
</template>

<script>
import axios from 'axios'

export default {
  name: "DiseaseSearchView",
  data() {
    return {
      search: {
        diseaseName: '',
        diseaseCode: '',
        diseaseICD: '',
        diseaseCategory: ''
      },
      disease_list: []
    }
  },
  methods: {
    cancel() {
      this.store.commit("setDiseaseSearchVisible", false)
    },
    confirm() {
      this.$emit("send", this.$refs.diseaseTable.getSelectionRows())
      this.store.commit("setDiseaseSearchVisible", false)
    },
    handleSearch() {
      axios({
        url: '/api/disease/query',
        method: 'post',
        data: this.search
      }).then(res => {
        this.disease_list = res.data.data
      }).catch(err => {
        console.log(err)
      }).then(() => {})
    }
  },
  props: [
      "store"
  ],
  computed: {
    diseaseSearchVisible: {
      get() {
        return this.store.state.diseaseSearchVisible
      },
      set(val) {
        this.store.commit("setDiseaseSearchVisible", val)
      }
    }
  }
}
</script>

<style scoped>

</style>